package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile){
        return wmMaterialService.uploadPicture(multipartFile);
    }

    @PostMapping("/list")
    public ResponseResult findList(@RequestBody WmMaterialDto dto){
        return wmMaterialService.findList(dto);
    }
    @GetMapping("del_picture/{id}")
    public ResponseResult deleteWmMaterial(@PathVariable Integer id){
        wmMaterialService.removeById(id);
        return ResponseResult.okResult("删除成功");
    }

    @GetMapping("collect/{id}")
    public ResponseResult collectWmMaterial(@PathVariable Integer id){
        wmMaterialService.lambdaUpdate()
                .set(WmMaterial::getIsCollection,1)
                .eq(WmMaterial::getId,id)
                .update();
        return ResponseResult.okResult("收藏成功");
    }

    @GetMapping("cancel_collect/{id}")
    public ResponseResult cancelCollectWmMaterial(@PathVariable Integer id){
        wmMaterialService.lambdaUpdate()
                .set(WmMaterial::getIsCollection,0)
                .eq(WmMaterial::getId,id)
                .update();
        return ResponseResult.okResult("取消收藏成功");
    }

}
